//
//  NSObject+HKExtension.swift
//  App架构Swift
//
//  Created by 胡锦涛 on 2019/2/19.
//  Copyright © 2019 胡锦涛. All rights reserved.
//

import UIKit

extension NSObject {
    
    /*
     使用例子 全局队列
     delay(by: 5, qosClass: .userInitiated) {
     print("时间2：", Date())
     }
     */
    public func hk_delay(by delayTime: TimeInterval, qosClass: DispatchQoS.QoSClass? = nil,
                         _ closure: @escaping () -> Void) {
        let dispatchQueue = qosClass != nil ? DispatchQueue.global(qos: qosClass!) : .main
        
        dispatchQueue.asyncAfter(
            deadline: DispatchTime.now() + delayTime, execute: closure
        )
    }
    
    ///[使用运行时]获取当前类所有的属性数组
    public func hk_propertyList() -> [String] {
        var properties:[String] = [String]()
        var count :UInt32 = 0
        //获取‘类’的属性列表
        let list = class_copyPropertyList(self.classForCoder, &count)
        print("属性的数量\(count)")
        for i in 0..<Int(count) {
            //根据下标 获取属性
            let a = list?[i]
            //获取属性的名称
            let cName = property_getName(a!)
            let n:String = String(utf8String:cName) ?? ""
            properties.append(n)
            print("\(n)\n")
        }
        return properties;
    }
    
}
